package jnpf.engine.util;

import cn.hutool.core.codec.Base64;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.map.MapUtil;
import jnpf.base.UserInfo;
import jnpf.emnus.SearchMethodEnum;
import jnpf.engine.custom.constants.BasicActivitiConstants;
import jnpf.engine.entity.FlowTaskEntity;
import jnpf.engine.model.flowengine.FlowModel;
import jnpf.engine.model.flowengine.shuntjson.childnode.*;
import jnpf.engine.model.flowengine.shuntjson.childnode.Properties;
import jnpf.engine.model.flowtask.FlowConditionModel;
import jnpf.permission.entity.UserEntity;
import jnpf.util.JsonUtil;
import jnpf.util.JsonUtilEx;
import jnpf.util.visiual.JnpfKeyConsts;
import org.apache.commons.lang3.ObjectUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.text.StringSubstitutor;
import org.flowable.bpmn.model.SequenceFlow;
import org.flowable.engine.HistoryService;
import org.flowable.engine.impl.util.CommandContextUtil;
import org.flowable.task.api.history.HistoricTaskInstance;
import org.flowable.task.service.impl.persistence.entity.HistoricTaskInstanceEntity;

import javax.script.ScriptEngine;
import javax.script.ScriptEngineManager;
import java.math.RoundingMode;
import java.text.NumberFormat;
import java.util.*;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import static jnpf.engine.custom.constants.BasicActivitiConstants.*;
import static jnpf.engine.custom.constants.BasicActivitiConstants.SEQUENCE_FLOW_WITH_CONDITION_EXPRESSION;

/**
 * @author Doctor4JavaEE
 * @since 2024/2/19
 */
public class EvalUtils {

    public static String assemConditionExpStr(String to, Properties properties, List<ProperCond> conditions,String nodeId) {
        Integer modeFlag = properties.getModeFlag();
        //用户模式
        if(modeFlag.equals(1)){
            Map<Long,String>  groupConditionMap= new HashMap<>();
            Boolean isCustomLogical = properties.getIsCustomLogical();
            List<CustomConditionGroupConfig> customLogical = properties.getCustomLogical();
            // 先判断是不是  转向节点, 如果是转向 节点, 那么不需要 set 一个 直接为true的表达式就可以,
//            else if(){
//
//            }
            //
            //
            //需要考虑选择分支的情况
            StringBuilder conditionExpressionStr = new StringBuilder();
            conditionExpressionStr.append("${ ");
            for (int i = 0; i < conditions.size(); i++) {
                conditionExpressionStr.append(" ( ");
                //
                ProperCond properCond = conditions.get(i);
                List<GroupsModel> groups = properCond.getGroups();

                StringBuilder groupConditionExp =new StringBuilder();

                for (int j = 0; j < groups.size(); j++) {
                    conditionExpressionStr.append(" ");
                    GroupsModel groupsModel = groups.get(j);
                    String field = groupsModel.getField();
                    int fieldType = groupsModel.getFieldType();
                    String jnpfKey = groupsModel.getJnpfKey();
                    String symbol = groupsModel.getSymbol();
                    Object fieldValue = groupsModel.getFieldValue();
                    String format = groupsModel.getFormat();
                    String valueFormat = groupsModel.getValueFormat();
                    String fieldValueJnpfKey = groupsModel.getFieldValueJnpfKey();
                    int fieldValueType = groupsModel.getFieldValueType();
                    String logic = groupsModel.getLogic();
                    if("isBlank".equals(symbol)){
                        Map map = new HashMap<>();
                        map.put("jnpfKey", String.format("\"%s\"", jnpfKey));//字符串
                        map.put("jnpfKeyType", fieldType);
                        map.put("filedName", String.format("\"%s\"", field));
                        StringSubstitutor stringSubstitutor = new StringSubstitutor(map);
                        String blankStr=CONDITION_CLASS+"isBlank( execution,${jnpfKey},${jnpfKeyType},${filedName} )";
                        String replace = stringSubstitutor.replace(blankStr);
                        conditionExpressionStr.append(replace);
                        if(Boolean.TRUE.equals(isCustomLogical)){
                            groupConditionExp.append(replace);
                        }
                    }
                    else if("isNotBlank".equals(symbol)){
                        Map map = new HashMap<>();
                        map.put("jnpfKey", String.format("\"%s\"", jnpfKey));//字符串
                        map.put("jnpfKeyType", fieldType);
                        map.put("filedName", String.format("\"%s\"", field));
                        StringSubstitutor stringSubstitutor = new StringSubstitutor(map);
                        String blankStr=CONDITION_CLASS+"isNotBlank( execution,${jnpfKey},${jnpfKeyType},${filedName} )";
                        String replace = stringSubstitutor.replace(blankStr);
                        conditionExpressionStr.append(replace);
                        if(Boolean.TRUE.equals(isCustomLogical)){
                            groupConditionExp.append(replace);
                        }
                    }
                    else if("==".equals(symbol)){
                        Map map = new HashMap<>();
                        map.put("jnpfKey", String.format("\"%s\"", jnpfKey));//字符串
                        map.put("jnpfKeyType", fieldType);
                        map.put("filedName", String.format("\"%s\"", field));
                        map.put("jnpfValueKey",  String.format("\"%s\"", fieldValueJnpfKey));
                        map.put("jnpfValueType", fieldValueType);

                        String jsonStr = JsonUtilEx.getObjectToString(fieldValue);
                        map.put("jnpfValue", String.format("\"%s\"", cn.hutool.core.codec.Base64.encode(jsonStr)));
                        StringSubstitutor stringSubstitutor = new StringSubstitutor(map);
                        String blankStr=CONDITION_CLASS+"equals( execution,${jnpfKey},${jnpfKeyType},${filedName},${jnpfValueKey},${jnpfValueType},${jnpfValue} )";
                        String replace = stringSubstitutor.replace(blankStr);
                        conditionExpressionStr.append(replace);
                        if(Boolean.TRUE.equals(isCustomLogical)){
                            groupConditionExp.append(replace);
                        }
                    }
                    else if("<>".equals(symbol)){
                        Map map = new HashMap<>();
                        map.put("jnpfKey", String.format("\"%s\"", jnpfKey));//字符串
                        map.put("jnpfKeyType", fieldType);
                        map.put("filedName", String.format("\"%s\"", field));
                        map.put("jnpfValueKey",  String.format("\"%s\"", fieldValueJnpfKey));
                        map.put("jnpfValueType", fieldValueType);

                        String jsonStr = JsonUtilEx.getObjectToString(fieldValue);
                        map.put("jnpfValue", String.format("\"%s\"", cn.hutool.core.codec.Base64.encode(jsonStr)));
                        StringSubstitutor stringSubstitutor = new StringSubstitutor(map);
                        String blankStr=CONDITION_CLASS+"notEquals( execution,${jnpfKey},${jnpfKeyType},${filedName},${jnpfValueKey},${jnpfValueType},${jnpfValue} )";
                        String replace = stringSubstitutor.replace(blankStr);
                        conditionExpressionStr.append(replace);
                        if(Boolean.TRUE.equals(isCustomLogical)){
                            groupConditionExp.append(replace);
                        }
                    }
                    else if(">".equals(symbol)){
                        Map map = new HashMap<>();
                        map.put("jnpfKey", String.format("\"%s\"", jnpfKey));//字符串
                        map.put("jnpfKeyType", fieldType);
                        map.put("filedName", String.format("\"%s\"", field));
                        map.put("jnpfValueKey",  String.format("\"%s\"", fieldValueJnpfKey));
                        map.put("jnpfValueType", fieldValueType);

                        String jsonStr = JsonUtilEx.getObjectToString(fieldValue);
                        map.put("jnpfValue", String.format("\"%s\"", cn.hutool.core.codec.Base64.encode(jsonStr)));
                        StringSubstitutor stringSubstitutor = new StringSubstitutor(map);
                        String blankStr=CONDITION_CLASS+"daYu( execution,${jnpfKey},${jnpfKeyType},${filedName},${jnpfValueKey},${jnpfValueType},${jnpfValue} )";
                        String replace = stringSubstitutor.replace(blankStr);
                        conditionExpressionStr.append(replace);
                        if(Boolean.TRUE.equals(isCustomLogical)){
                            groupConditionExp.append(replace);
                        }
                    }
                    else if("<".equals(symbol)){
                        Map map = new HashMap<>();
                        map.put("jnpfKey", String.format("\"%s\"", jnpfKey));//字符串
                        map.put("jnpfKeyType", fieldType);
                        map.put("filedName", String.format("\"%s\"", field));
                        map.put("jnpfValueKey",  String.format("\"%s\"", fieldValueJnpfKey));
                        map.put("jnpfValueType", fieldValueType);

                        String jsonStr = JsonUtilEx.getObjectToString(fieldValue);
                        map.put("jnpfValue", String.format("\"%s\"", cn.hutool.core.codec.Base64.encode(jsonStr)));
                        StringSubstitutor stringSubstitutor = new StringSubstitutor(map);
                        String blankStr=CONDITION_CLASS+"xiaoYu( execution,${jnpfKey},${jnpfKeyType},${filedName},${jnpfValueKey},${jnpfValueType},${jnpfValue} )";
                        String replace = stringSubstitutor.replace(blankStr);
                        conditionExpressionStr.append(replace);
                        if(Boolean.TRUE.equals(isCustomLogical)){
                            groupConditionExp.append(replace);
                        }
                    }
                    else if(">=".equals(symbol)){
                        Map map = new HashMap<>();
                        map.put("jnpfKey", String.format("\"%s\"", jnpfKey));//字符串
                        map.put("jnpfKeyType", fieldType);
                        map.put("filedName", String.format("\"%s\"", field));
                        map.put("jnpfValueKey",  String.format("\"%s\"", fieldValueJnpfKey));
                        map.put("jnpfValueType", fieldValueType);

                        String jsonStr = JsonUtilEx.getObjectToString(fieldValue);
                        map.put("jnpfValue", String.format("\"%s\"", cn.hutool.core.codec.Base64.encode(jsonStr)));
                        StringSubstitutor stringSubstitutor = new StringSubstitutor(map);
                        String blankStr=CONDITION_CLASS+"daDengYu( execution,${jnpfKey},${jnpfKeyType},${filedName},${jnpfValueKey},${jnpfValueType},${jnpfValue} )";
                        String replace = stringSubstitutor.replace(blankStr);
                        conditionExpressionStr.append(replace);
                        if(Boolean.TRUE.equals(isCustomLogical)){
                            groupConditionExp.append(replace);
                        }
                    }
                    else if("<=".equals(symbol)){
                        Map map = new HashMap<>();
                        map.put("jnpfKey", String.format("\"%s\"", jnpfKey));//字符串
                        map.put("jnpfKeyType", fieldType);
                        map.put("filedName", String.format("\"%s\"", field));
                        map.put("jnpfValueKey",  String.format("\"%s\"", fieldValueJnpfKey));
                        map.put("jnpfValueType", fieldValueType);

                        String jsonStr = JsonUtilEx.getObjectToString(fieldValue);
                        map.put("jnpfValue", String.format("\"%s\"", cn.hutool.core.codec.Base64.encode(jsonStr)));
                        StringSubstitutor stringSubstitutor = new StringSubstitutor(map);
                        String blankStr=CONDITION_CLASS+"xiaoDengYu( execution,${jnpfKey},${jnpfKeyType},${filedName},${jnpfValueKey},${jnpfValueType},${jnpfValue} )";
                        String replace = stringSubstitutor.replace(blankStr);
                        conditionExpressionStr.append(replace);
                        if(Boolean.TRUE.equals(isCustomLogical)){
                            groupConditionExp.append(replace);
                        }

                    }
                    else if("like".equals(symbol)){
                        Map map = new HashMap<>();
                        map.put("jnpfKey", String.format("\"%s\"", jnpfKey));//字符串
                        map.put("jnpfKeyType", fieldType);
                        map.put("filedName", String.format("\"%s\"", field));
                        map.put("jnpfValueKey",  String.format("\"%s\"", fieldValueJnpfKey));
                        map.put("jnpfValueType", fieldValueType);

                        String jsonStr = JsonUtilEx.getObjectToString(fieldValue);
                        map.put("jnpfValue", String.format("\"%s\"", cn.hutool.core.codec.Base64.encode(jsonStr)));
                        StringSubstitutor stringSubstitutor = new StringSubstitutor(map);
                        String blankStr=CONDITION_CLASS+"containsEx( execution,${jnpfKey},${jnpfKeyType},${filedName},${jnpfValueKey},${jnpfValueType},${jnpfValue} )";
                        String replace = stringSubstitutor.replace(blankStr);
                        conditionExpressionStr.append(replace);
                        if(Boolean.TRUE.equals(isCustomLogical)){
                            groupConditionExp.append(replace);
                        }
                    }
                    else if("notLike".equals(symbol)){
                        Map map = new HashMap<>();
                        map.put("jnpfKey", String.format("\"%s\"", jnpfKey));//字符串
                        map.put("jnpfKeyType", fieldType);
                        map.put("filedName", String.format("\"%s\"", field));
                        map.put("jnpfValueKey",  String.format("\"%s\"", fieldValueJnpfKey));
                        map.put("jnpfValueType", fieldValueType);

                        String jsonStr = JsonUtilEx.getObjectToString(fieldValue);
                        map.put("jnpfValue", String.format("\"%s\"", cn.hutool.core.codec.Base64.encode(jsonStr)));
                        StringSubstitutor stringSubstitutor = new StringSubstitutor(map);
                        String blankStr=CONDITION_CLASS+"notContainsEx( execution,${jnpfKey},${jnpfKeyType},${filedName},${jnpfValueKey},${jnpfValueType},${jnpfValue} )";
                        String replace = stringSubstitutor.replace(blankStr);
                        conditionExpressionStr.append(replace);
                        if(Boolean.TRUE.equals(isCustomLogical)){
                            groupConditionExp.append(replace);
                        }
                    }
                    else if("isStartWith".equals(symbol)){
                        Map map = new HashMap<>();
                        map.put("jnpfKey", String.format("\"%s\"", jnpfKey));//字符串
                        map.put("jnpfKeyType", fieldType);
                        map.put("filedName", String.format("\"%s\"", field));
                        map.put("jnpfValueKey",  String.format("\"%s\"", fieldValueJnpfKey));
                        map.put("jnpfValueType", fieldValueType);

                        String jsonStr = JsonUtilEx.getObjectToString(fieldValue);
                        map.put("jnpfValue", String.format("\"%s\"", cn.hutool.core.codec.Base64.encode(jsonStr)));
                        StringSubstitutor stringSubstitutor = new StringSubstitutor(map);
                        String blankStr=CONDITION_CLASS+"isStartWith( execution,${jnpfKey},${jnpfKeyType},${filedName},${jnpfValueKey},${jnpfValueType},${jnpfValue} )";
                        String replace = stringSubstitutor.replace(blankStr);
                        conditionExpressionStr.append(replace);
                        if(Boolean.TRUE.equals(isCustomLogical)){
                            groupConditionExp.append(replace);
                        }

                    }
                    else if("isStartNotWith".equals(symbol)){
                        Map map = new HashMap<>();
                        map.put("jnpfKey", String.format("\"%s\"", jnpfKey));//字符串
                        map.put("jnpfKeyType", fieldType);
                        map.put("filedName", String.format("\"%s\"", field));
                        map.put("jnpfValueKey",  String.format("\"%s\"", fieldValueJnpfKey));
                        map.put("jnpfValueType", fieldValueType);

                        String jsonStr = JsonUtilEx.getObjectToString(fieldValue);
                        map.put("jnpfValue", String.format("\"%s\"", cn.hutool.core.codec.Base64.encode(jsonStr)));
                        StringSubstitutor stringSubstitutor = new StringSubstitutor(map);
                        String blankStr=CONDITION_CLASS+"isStartNotWith( execution,${jnpfKey},${jnpfKeyType},${filedName},${jnpfValueKey},${jnpfValueType},${jnpfValue} )";
                        String replace = stringSubstitutor.replace(blankStr);
                        conditionExpressionStr.append(replace);
                        if(Boolean.TRUE.equals(isCustomLogical)){
                            groupConditionExp.append(replace);
                        }

                    }
                    else if("isEndWith".equals(symbol)){
                        Map map = new HashMap<>();
                        map.put("jnpfKey", String.format("\"%s\"", jnpfKey));//字符串
                        map.put("jnpfKeyType", fieldType);
                        map.put("filedName", String.format("\"%s\"", field));
                        map.put("jnpfValueKey",  String.format("\"%s\"", fieldValueJnpfKey));
                        map.put("jnpfValueType", fieldValueType);

                        String jsonStr = JsonUtilEx.getObjectToString(fieldValue);
                        map.put("jnpfValue", String.format("\"%s\"", cn.hutool.core.codec.Base64.encode(jsonStr)));
                        StringSubstitutor stringSubstitutor = new StringSubstitutor(map);
                        String blankStr=CONDITION_CLASS+"isEndWith( execution,${jnpfKey},${jnpfKeyType},${filedName},${jnpfValueKey},${jnpfValueType},${jnpfValue} )";
                        String replace = stringSubstitutor.replace(blankStr);
                        conditionExpressionStr.append(replace);
                        if(Boolean.TRUE.equals(isCustomLogical)){
                            groupConditionExp.append(replace);
                        }
                    }
                    else if("isEndNotWith".equals(symbol)){
                        Map map = new HashMap<>();
                        map.put("jnpfKey", String.format("\"%s\"", jnpfKey));//字符串
                        map.put("jnpfKeyType", fieldType);
                        map.put("filedName", String.format("\"%s\"", field));
                        map.put("jnpfValueKey",  String.format("\"%s\"", fieldValueJnpfKey));
                        map.put("jnpfValueType", fieldValueType);

                        String jsonStr = JsonUtilEx.getObjectToString(fieldValue);
                        map.put("jnpfValue", String.format("\"%s\"", cn.hutool.core.codec.Base64.encode(jsonStr)));
                        StringSubstitutor stringSubstitutor = new StringSubstitutor(map);
                        String blankStr=CONDITION_CLASS+"isEndNotWith( execution,${jnpfKey},${jnpfKeyType},${filedName},${jnpfValueKey},${jnpfValueType},${jnpfValue} )";
                        String replace = stringSubstitutor.replace(blankStr);
                        conditionExpressionStr.append(replace);
                        if(Boolean.TRUE.equals(isCustomLogical)){
                            groupConditionExp.append(replace);
                        }
                    }
                    else if("isNumberValueScope".equals(symbol)){
                        List<Long> fieldValueList= (List<Long>)fieldValue;
                        Map map = new HashMap<>();
                        map.put("jnpfKey", String.format("\"%s\"", JnpfKeyConsts.NUM_INPUT));//字符串
                        map.put("jnpfKeyType", fieldType);
                        map.put("filedName", String.format("\"%s\"", field));
                        map.put("jnpfValueKey",  String.format("\"%s\"", JnpfKeyConsts.NUM_INPUT));
                        map.put("jnpfValueType", fieldValueType);

                        String jsonStr = JsonUtilEx.getObjectToString(fieldValueList.get(0));
                        map.put("jnpfValue", String.format("\"%s\"", cn.hutool.core.codec.Base64.encode(jsonStr)));


                        map.put("jnpfValueKey1", String.format("\"%s\"", JnpfKeyConsts.NUM_INPUT));
                        map.put("jnpfValueType1", fieldValueType);
                        String jsonStr1 = JsonUtilEx.getObjectToString(fieldValueList.get(1));
                        map.put("jnpfValue1", String.format("\"%s\"", cn.hutool.core.codec.Base64.encode(jsonStr1)));
                        StringSubstitutor stringSubstitutor = new StringSubstitutor(map);
                        String blankStr=CONDITION_CLASS+"isNumberValueScope( execution,${jnpfKey},${jnpfKeyType},${filedName},${jnpfValueKey},${jnpfValueType},${jnpfValue} ,${jnpfValueKey1},${jnpfValueType1},${jnpfValue1} )";
                        String replace = stringSubstitutor.replace(blankStr);
                        conditionExpressionStr.append(replace);
                        if(Boolean.TRUE.equals(isCustomLogical)){
                            groupConditionExp.append(replace);
                        }
                    }
                    else if("isNumberValueScope1".equals(symbol)){
                        List<Long> fieldValueList= (List<Long>)fieldValue;
                        Map map = new HashMap<>();
                        map.put("jnpfKey", String.format("\"%s\"", JnpfKeyConsts.NUM_INPUT));//字符串
                        map.put("jnpfKeyType", fieldType);
                        map.put("filedName", String.format("\"%s\"", field));
                        map.put("jnpfValueKey",  String.format("\"%s\"", JnpfKeyConsts.NUM_INPUT));
                        map.put("jnpfValueType", fieldValueType);

                        String jsonStr = JsonUtilEx.getObjectToString(fieldValueList.get(0));
                        map.put("jnpfValue", String.format("\"%s\"", cn.hutool.core.codec.Base64.encode(jsonStr)));


                        map.put("jnpfValueKey1", String.format("\"%s\"", JnpfKeyConsts.NUM_INPUT));
                        map.put("jnpfValueType1", fieldValueType);
                        String jsonStr1 = JsonUtilEx.getObjectToString(fieldValueList.get(1));
                        map.put("jnpfValue1", String.format("\"%s\"", cn.hutool.core.codec.Base64.encode(jsonStr1)));
                        StringSubstitutor stringSubstitutor = new StringSubstitutor(map);
                        String blankStr=CONDITION_CLASS+"isNumberValueScope1( execution,${jnpfKey},${jnpfKeyType},${filedName},${jnpfValueKey},${jnpfValueType},${jnpfValue} ,${jnpfValueKey1},${jnpfValueType1},${jnpfValue1} )";
                        String replace = stringSubstitutor.replace(blankStr);
                        conditionExpressionStr.append(replace);
                        if(Boolean.TRUE.equals(isCustomLogical)){
                            groupConditionExp.append(replace);
                        }
                    }
                    else if("isNumberValueScope2".equals(symbol)){
                        List<Long> fieldValueList= (List<Long>)fieldValue;
                        Map map = new HashMap<>();
                        map.put("jnpfKey", String.format("\"%s\"", JnpfKeyConsts.NUM_INPUT));//字符串
                        map.put("jnpfKeyType", fieldType);
                        map.put("filedName", String.format("\"%s\"", field));
                        map.put("jnpfValueKey",  String.format("\"%s\"", JnpfKeyConsts.NUM_INPUT));
                        map.put("jnpfValueType", fieldValueType);

                        String jsonStr = JsonUtilEx.getObjectToString(fieldValueList.get(0));
                        map.put("jnpfValue", String.format("\"%s\"", cn.hutool.core.codec.Base64.encode(jsonStr)));


                        map.put("jnpfValueKey1", String.format("\"%s\"", JnpfKeyConsts.NUM_INPUT));
                        map.put("jnpfValueType1", fieldValueType);
                        String jsonStr1 = JsonUtilEx.getObjectToString(fieldValueList.get(1));
                        map.put("jnpfValue1", String.format("\"%s\"", cn.hutool.core.codec.Base64.encode(jsonStr1)));
                        StringSubstitutor stringSubstitutor = new StringSubstitutor(map);
                        String blankStr=CONDITION_CLASS+"isNumberValueScope2( execution,${jnpfKey},${jnpfKeyType},${filedName},${jnpfValueKey},${jnpfValueType},${jnpfValue} ,${jnpfValueKey1},${jnpfValueType1},${jnpfValue1} )";
                        String replace = stringSubstitutor.replace(blankStr);
                        conditionExpressionStr.append(replace);
                        if(Boolean.TRUE.equals(isCustomLogical)){
                            groupConditionExp.append(replace);
                        }
                    }
                    else if("isNumberValueScope3".equals(symbol)){
                        List<Long> fieldValueList= (List<Long>)fieldValue;
                        Map map = new HashMap<>();
                        map.put("jnpfKey", String.format("\"%s\"", JnpfKeyConsts.NUM_INPUT));//字符串
                        map.put("jnpfKeyType", fieldType);
                        map.put("filedName", String.format("\"%s\"", field));
                        map.put("jnpfValueKey",  String.format("\"%s\"", JnpfKeyConsts.NUM_INPUT));
                        map.put("jnpfValueType", fieldValueType);

                        String jsonStr = JsonUtilEx.getObjectToString(fieldValueList.get(0));
                        map.put("jnpfValue", String.format("\"%s\"", cn.hutool.core.codec.Base64.encode(jsonStr)));


                        map.put("jnpfValueKey1", String.format("\"%s\"", JnpfKeyConsts.NUM_INPUT));
                        map.put("jnpfValueType1", fieldValueType);
                        String jsonStr1 = JsonUtilEx.getObjectToString(fieldValueList.get(1));
                        map.put("jnpfValue1", String.format("\"%s\"", cn.hutool.core.codec.Base64.encode(jsonStr1)));
                        StringSubstitutor stringSubstitutor = new StringSubstitutor(map);
                        String blankStr=CONDITION_CLASS+"isNumberValueScope3( execution,${jnpfKey},${jnpfKeyType},${filedName},${jnpfValueKey},${jnpfValueType},${jnpfValue} ,${jnpfValueKey1},${jnpfValueType1},${jnpfValue1} )";
                        String replace = stringSubstitutor.replace(blankStr);
                        conditionExpressionStr.append(replace);
                        if(Boolean.TRUE.equals(isCustomLogical)){
                            groupConditionExp.append(replace);
                        }
                    }
                    else if("isBefore".equals(symbol)){
                        Map map = new HashMap<>();
                        map.put("jnpfKey", String.format("\"%s\"", jnpfKey));//字符串
                        map.put("jnpfKeyType", fieldType);
                        map.put("filedName", String.format("\"%s\"", field));

                        map.put("nameFormat", String.format("\"%s\"", format));

                        if(StringUtils.isBlank(valueFormat)){
                            map.put("valueFormat", String.format("\"%s\"", format));
                        }
                        else{
                            map.put("valueFormat", String.format("\"%s\"", valueFormat));
                        }

                        if(StringUtils.isBlank(fieldValueJnpfKey)){
                            map.put("jnpfValueKey",  String.format("\"%s\"", jnpfKey));
                        }
                        else{
                            map.put("jnpfValueKey",  String.format("\"%s\"", fieldValueJnpfKey));
                        }

                        map.put("jnpfValueType", fieldValueType);
                        String jsonStr = JsonUtilEx.getObjectToString(fieldValue);
                        map.put("jnpfValue", String.format("\"%s\"", cn.hutool.core.codec.Base64.encode(jsonStr)));
                        StringSubstitutor stringSubstitutor = new StringSubstitutor(map);
                        String blankStr=CONDITION_CLASS+"isBefore( execution,${jnpfKey},${jnpfKeyType},${filedName},${nameFormat},${jnpfValueKey},${jnpfValueType},${jnpfValue},${valueFormat} )";
                        String replace = stringSubstitutor.replace(blankStr);
                        conditionExpressionStr.append(replace);
                        if(Boolean.TRUE.equals(isCustomLogical)){
                            groupConditionExp.append(replace);
                        }
                    }
                    else if("isAfter".equals(symbol)){
                        Map map = new HashMap<>();
                        map.put("jnpfKey", String.format("\"%s\"", jnpfKey));//字符串
                        map.put("jnpfKeyType", fieldType);
                        map.put("filedName", String.format("\"%s\"", field));

                        map.put("nameFormat", String.format("\"%s\"", format));

                        if(StringUtils.isBlank(valueFormat)){
                            map.put("valueFormat", String.format("\"%s\"", format));
                        }
                        else{
                            map.put("valueFormat", String.format("\"%s\"", valueFormat));
                        }

                        if(StringUtils.isBlank(fieldValueJnpfKey)){
                            map.put("jnpfValueKey",  String.format("\"%s\"", jnpfKey));
                        }
                        else{
                            map.put("jnpfValueKey",  String.format("\"%s\"", fieldValueJnpfKey));
                        }
                        map.put("jnpfValueType", fieldValueType);
                        String jsonStr = JsonUtilEx.getObjectToString(fieldValue);
                        map.put("jnpfValue", String.format("\"%s\"", cn.hutool.core.codec.Base64.encode(jsonStr)));
                        StringSubstitutor stringSubstitutor = new StringSubstitutor(map);
                        String blankStr=CONDITION_CLASS+"isAfter( execution,${jnpfKey},${jnpfKeyType},${filedName},${nameFormat},${jnpfValueKey},${jnpfValueType},${jnpfValue},${valueFormat} )";
                        String replace = stringSubstitutor.replace(blankStr);
                        conditionExpressionStr.append(replace);
                        if(Boolean.TRUE.equals(isCustomLogical)){
                            groupConditionExp.append(replace);
                        }
                    }
                    else if("isBeforeAndEquals".equals(symbol)){
                        Map map = new HashMap<>();
                        map.put("jnpfKey", String.format("\"%s\"", jnpfKey));//字符串
                        map.put("jnpfKeyType", fieldType);
                        map.put("filedName", String.format("\"%s\"", field));

                        map.put("nameFormat", String.format("\"%s\"", format));

                        if(StringUtils.isBlank(valueFormat)){
                            map.put("valueFormat", String.format("\"%s\"", format));
                        }
                        else{
                            map.put("valueFormat", String.format("\"%s\"", valueFormat));
                        }

                        if(StringUtils.isBlank(fieldValueJnpfKey)){
                            map.put("jnpfValueKey",  String.format("\"%s\"", jnpfKey));
                        }
                        else{
                            map.put("jnpfValueKey",  String.format("\"%s\"", fieldValueJnpfKey));
                        }
                        map.put("jnpfValueType", fieldValueType);
                        String jsonStr = JsonUtilEx.getObjectToString(fieldValue);
                        map.put("jnpfValue", String.format("\"%s\"", cn.hutool.core.codec.Base64.encode(jsonStr)));
                        StringSubstitutor stringSubstitutor = new StringSubstitutor(map);
                        String blankStr=CONDITION_CLASS+"isBeforeAndEquals( execution,${jnpfKey},${jnpfKeyType},${filedName},${nameFormat},${jnpfValueKey},${jnpfValueType},${jnpfValue},${valueFormat} )";
                        String replace = stringSubstitutor.replace(blankStr);
                        conditionExpressionStr.append(replace);
                        if(Boolean.TRUE.equals(isCustomLogical)){
                            groupConditionExp.append(replace);
                        }
                    }
                    else if("isAfterAndEquals".equals(symbol)){
                        Map map = new HashMap<>();
                        map.put("jnpfKey", String.format("\"%s\"", jnpfKey));//字符串
                        map.put("jnpfKeyType", fieldType);
                        map.put("filedName", String.format("\"%s\"", field));

                        map.put("nameFormat", String.format("\"%s\"", format));

                        if(StringUtils.isBlank(valueFormat)){
                            map.put("valueFormat", String.format("\"%s\"", format));
                        }
                        else{
                            map.put("valueFormat", String.format("\"%s\"", valueFormat));
                        }

                        if(StringUtils.isBlank(fieldValueJnpfKey)){
                            map.put("jnpfValueKey",  String.format("\"%s\"", jnpfKey));
                        }
                        else{
                            map.put("jnpfValueKey",  String.format("\"%s\"", fieldValueJnpfKey));
                        }
                        map.put("jnpfValueType", fieldValueType);
                        String jsonStr = JsonUtilEx.getObjectToString(fieldValue);
                        map.put("jnpfValue", String.format("\"%s\"", cn.hutool.core.codec.Base64.encode(jsonStr)));
                        StringSubstitutor stringSubstitutor = new StringSubstitutor(map);
                        String blankStr=CONDITION_CLASS+"isAfterAndEquals( execution,${jnpfKey},${jnpfKeyType},${filedName},${nameFormat},${jnpfValueKey},${jnpfValueType},${jnpfValue},${valueFormat} )";
                        String replace = stringSubstitutor.replace(blankStr);
                        conditionExpressionStr.append(replace);
                        if(Boolean.TRUE.equals(isCustomLogical)){
                            groupConditionExp.append(replace);
                        }
                    }
                    else if("isTimeScope".equals(symbol)){
                        List<Long> fieldValueList= (List<Long>)fieldValue;
                        Map map = new HashMap<>();
                        map.put("jnpfKey", String.format("\"%s\"", jnpfKey));//字符串
                        map.put("jnpfKeyType", fieldType);
                        map.put("filedName", String.format("\"%s\"", field));
                        map.put("nameFormat", String.format("\"%s\"", format));

                        if(StringUtils.isBlank(valueFormat)){
                            map.put("valueFormat", String.format("\"%s\"", format));
                            map.put("valueFormat1", String.format("\"%s\"", format));
                        }
                        else{
                            map.put("valueFormat", String.format("\"%s\"", valueFormat));
                            map.put("valueFormat1", String.format("\"%s\"", valueFormat));
                        }

                        if(StringUtils.isBlank(fieldValueJnpfKey)){
                            map.put("jnpfValueKey",  String.format("\"%s\"", jnpfKey));
                            map.put("jnpfValueKey1",  String.format("\"%s\"", jnpfKey));
                        }
                        else{
                            map.put("jnpfValueKey",  String.format("\"%s\"", fieldValueJnpfKey));
                            map.put("jnpfValueKey1",  String.format("\"%s\"", fieldValueJnpfKey));
                        }

                        map.put("jnpfValueType", fieldValueType);

                        String jsonStr = JsonUtilEx.getObjectToString(fieldValueList.get(0));
                        map.put("jnpfValue", String.format("\"%s\"", cn.hutool.core.codec.Base64.encode(jsonStr)));


                        map.put("jnpfValueType1", fieldValueType);
                        String jsonStr1 = JsonUtilEx.getObjectToString(fieldValueList.get(1));
                        map.put("jnpfValue1", String.format("\"%s\"", cn.hutool.core.codec.Base64.encode(jsonStr1)));
                        StringSubstitutor stringSubstitutor = new StringSubstitutor(map);
                        String blankStr=CONDITION_CLASS+"isTimeScope( execution,${jnpfKey},${jnpfKeyType},${filedName},${nameFormat},${jnpfValueKey},${jnpfValueType},${jnpfValue},${valueFormat} ,${jnpfValueKey1},${jnpfValueType1},${jnpfValue1} ,${valueFormat1})";
                        String replace = stringSubstitutor.replace(blankStr);
                        conditionExpressionStr.append(replace);
                        if(Boolean.TRUE.equals(isCustomLogical)){
                            groupConditionExp.append(replace);
                        }
                    }
                    else if("isNotTimeScope".equals(symbol)){
                        List<Long> fieldValueList= (List<Long>)fieldValue;
                        Map map = new HashMap<>();
                        map.put("jnpfKey", String.format("\"%s\"", jnpfKey));//字符串
                        map.put("jnpfKeyType", fieldType);
                        map.put("filedName", String.format("\"%s\"", field));
                        map.put("nameFormat", String.format("\"%s\"", format));

                        if(StringUtils.isBlank(valueFormat)){
                            map.put("valueFormat", String.format("\"%s\"", format));
                            map.put("valueFormat1", String.format("\"%s\"", format));
                        }
                        else{
                            map.put("valueFormat", String.format("\"%s\"", valueFormat));
                            map.put("valueFormat1", String.format("\"%s\"", valueFormat));
                        }

                        if(StringUtils.isBlank(fieldValueJnpfKey)){
                            map.put("jnpfValueKey",  String.format("\"%s\"", jnpfKey));
                            map.put("jnpfValueKey1",  String.format("\"%s\"", jnpfKey));
                        }
                        else{
                            map.put("jnpfValueKey",  String.format("\"%s\"", fieldValueJnpfKey));
                            map.put("jnpfValueKey1",  String.format("\"%s\"", fieldValueJnpfKey));
                        }

                        map.put("jnpfValueType", fieldValueType);

                        String jsonStr = JsonUtilEx.getObjectToString(fieldValueList.get(0));
                        map.put("jnpfValue", String.format("\"%s\"", cn.hutool.core.codec.Base64.encode(jsonStr)));

                        map.put("jnpfValueType1", fieldValueType);
                        String jsonStr1 = JsonUtilEx.getObjectToString(fieldValueList.get(1));
                        map.put("jnpfValue1", String.format("\"%s\"", cn.hutool.core.codec.Base64.encode(jsonStr1)));
                        StringSubstitutor stringSubstitutor = new StringSubstitutor(map);
                        String blankStr=CONDITION_CLASS+"isNotTimeScope( execution,${jnpfKey},${jnpfKeyType},${filedName},${nameFormat},${jnpfValueKey},${jnpfValueType},${jnpfValue},${valueFormat} ,${jnpfValueKey1},${jnpfValueType1},${jnpfValue1} ,${valueFormat1})";
                        String replace = stringSubstitutor.replace(blankStr);
                        conditionExpressionStr.append(replace);
                        if(Boolean.TRUE.equals(isCustomLogical)){
                            groupConditionExp.append(replace);
                        }
                    }
                    else if("isBelong".equals(symbol)){
                        Map map = new HashMap<>();
                        map.put("jnpfKey", String.format("\"%s\"", jnpfKey));//字符串
                        map.put("jnpfKeyType", fieldType);
                        map.put("filedName", String.format("\"%s\"", field));

                        if(StringUtils.isBlank(fieldValueJnpfKey)){
                            map.put("jnpfValueKey",  String.format("\"%s\"", jnpfKey));
                        }
                        else{
                            map.put("jnpfValueKey",  String.format("\"%s\"", fieldValueJnpfKey));
                        }

                        map.put("jnpfValueType", fieldValueType);

                        String jsonStr = JsonUtilEx.getObjectToString(fieldValue);
                        map.put("jnpfValue", String.format("\"%s\"", cn.hutool.core.codec.Base64.encode(jsonStr)));
                        StringSubstitutor stringSubstitutor = new StringSubstitutor(map);
                        String blankStr=CONDITION_CLASS+"isBelong( execution,${jnpfKey},${jnpfKeyType},${filedName},${jnpfValueKey},${jnpfValueType},${jnpfValue} )";
                        String replace = stringSubstitutor.replace(blankStr);
                        conditionExpressionStr.append(replace);
                        if(Boolean.TRUE.equals(isCustomLogical)){
                            groupConditionExp.append(replace);
                        }
                    }
                    else if("isNotBelong".equals(symbol)){
                        Map map = new HashMap<>();
                        map.put("jnpfKey", String.format("\"%s\"", jnpfKey));//字符串
                        map.put("jnpfKeyType", fieldType);
                        map.put("filedName", String.format("\"%s\"", field));
                        if(StringUtils.isBlank(fieldValueJnpfKey)){
                            map.put("jnpfValueKey",  String.format("\"%s\"", jnpfKey));
                        }
                        else{
                            map.put("jnpfValueKey",  String.format("\"%s\"", fieldValueJnpfKey));
                        }
                        map.put("jnpfValueType", fieldValueType);

                        String jsonStr = JsonUtilEx.getObjectToString(fieldValue);
                        map.put("jnpfValue", String.format("\"%s\"", cn.hutool.core.codec.Base64.encode(jsonStr)));
                        StringSubstitutor stringSubstitutor = new StringSubstitutor(map);
                        String blankStr=CONDITION_CLASS+"isNotBelong( execution,${jnpfKey},${jnpfKeyType},${filedName},${jnpfValueKey},${jnpfValueType},${jnpfValue} )";
                        String replace = stringSubstitutor.replace(blankStr);
                        conditionExpressionStr.append(replace);
                        if(Boolean.TRUE.equals(isCustomLogical)){
                            groupConditionExp.append(replace);
                        }
                    }
                    else if("isSubBelong".equals(symbol)){
                        Map map = new HashMap<>();
                        map.put("jnpfKey", String.format("\"%s\"", jnpfKey));//字符串
                        map.put("jnpfKeyType", fieldType);
                        map.put("filedName", String.format("\"%s\"", field));
                        if(StringUtils.isBlank(fieldValueJnpfKey)){
                            map.put("jnpfValueKey",  String.format("\"%s\"", jnpfKey));
                        }
                        else{
                            map.put("jnpfValueKey",  String.format("\"%s\"", fieldValueJnpfKey));
                        }
                        map.put("jnpfValueType", fieldValueType);

                        String jsonStr = JsonUtilEx.getObjectToString(fieldValue);
                        map.put("jnpfValue", String.format("\"%s\"", cn.hutool.core.codec.Base64.encode(jsonStr)));
                        StringSubstitutor stringSubstitutor = new StringSubstitutor(map);
                        String blankStr=CONDITION_CLASS+"isSubBelong( execution,${jnpfKey},${jnpfKeyType},${filedName},${jnpfValueKey},${jnpfValueType},${jnpfValue} )";
                        String replace = stringSubstitutor.replace(blankStr);
                        conditionExpressionStr.append(replace);
                        if(Boolean.TRUE.equals(isCustomLogical)){
                            groupConditionExp.append(replace);
                        }
                    }
                    else if("isSubNotBelong".equals(symbol)){
                        Map map = new HashMap<>();
                        map.put("jnpfKey", String.format("\"%s\"", jnpfKey));//字符串
                        map.put("jnpfKeyType", fieldType);
                        map.put("filedName", String.format("\"%s\"", field));
                        if(StringUtils.isBlank(fieldValueJnpfKey)){
                            map.put("jnpfValueKey",  String.format("\"%s\"", jnpfKey));
                        }
                        else{
                            map.put("jnpfValueKey",  String.format("\"%s\"", fieldValueJnpfKey));
                        }
                        map.put("jnpfValueType", fieldValueType);

                        String jsonStr = JsonUtilEx.getObjectToString(fieldValue);
                        map.put("jnpfValue", String.format("\"%s\"", Base64.encode(jsonStr)));
                        StringSubstitutor stringSubstitutor = new StringSubstitutor(map);
                        String blankStr=CONDITION_CLASS+"isSubNotBelong( execution,${jnpfKey},${jnpfKeyType},${filedName},${jnpfValueKey},${jnpfValueType},${jnpfValue} )";
                        String replace = stringSubstitutor.replace(blankStr);
                        conditionExpressionStr.append(replace);
                        if(Boolean.TRUE.equals(isCustomLogical)){
                            groupConditionExp.append(replace);
                        }
                    }
                    else if("belongDept".equals(symbol)){
                        Map map = new HashMap<>();
                        map.put("jnpfKey", String.format("\"%s\"", jnpfKey));//字符串
                        map.put("jnpfKeyType", fieldType);
                        map.put("filedName", String.format("\"%s\"", field));

                        if(StringUtils.isBlank(fieldValueJnpfKey)){
                            map.put("jnpfValueKey",  String.format("\"%s\"", JnpfKeyConsts.COMSELECT));
                        }
                        else{
                            map.put("jnpfValueKey",  String.format("\"%s\"", fieldValueJnpfKey));
                        }

                        map.put("jnpfValueType", fieldValueType);

                        String jsonStr = JsonUtilEx.getObjectToString(fieldValue);
                        map.put("jnpfValue", String.format("\"%s\"", cn.hutool.core.codec.Base64.encode(jsonStr)));
                        StringSubstitutor stringSubstitutor = new StringSubstitutor(map);
                        String blankStr=CONDITION_CLASS+"belongDept( execution,${jnpfKey},${jnpfKeyType},${filedName},${jnpfValueKey},${jnpfValueType},${jnpfValue} )";
                        String replace = stringSubstitutor.replace(blankStr);
                        conditionExpressionStr.append(replace);
                        if(Boolean.TRUE.equals(isCustomLogical)){
                            groupConditionExp.append(replace);
                        }
                    }
                    else if("belongRole".equals(symbol)){
                        Map map = new HashMap<>();
                        map.put("jnpfKey", String.format("\"%s\"", jnpfKey));//字符串
                        map.put("jnpfKeyType", fieldType);
                        map.put("filedName", String.format("\"%s\"", field));

                        if(StringUtils.isBlank(fieldValueJnpfKey)){
                            map.put("jnpfValueKey",  String.format("\"%s\"", JnpfKeyConsts.ROLESELECT));
                        }
                        else{
                            map.put("jnpfValueKey",  String.format("\"%s\"", fieldValueJnpfKey));
                        }

                        map.put("jnpfValueType", fieldValueType);

                        String jsonStr = JsonUtilEx.getObjectToString(fieldValue);
                        map.put("jnpfValue", String.format("\"%s\"", cn.hutool.core.codec.Base64.encode(jsonStr)));
                        StringSubstitutor stringSubstitutor = new StringSubstitutor(map);
                        String blankStr=CONDITION_CLASS+"belongRole( execution,${jnpfKey},${jnpfKeyType},${filedName},${jnpfValueKey},${jnpfValueType},${jnpfValue} )";
                        String replace = stringSubstitutor.replace(blankStr);
                        conditionExpressionStr.append(replace);
                        if(Boolean.TRUE.equals(isCustomLogical)){
                            groupConditionExp.append(replace);
                        }
                    }
                    else if("belongPos".equals(symbol)){
                        Map map = new HashMap<>();
                        map.put("jnpfKey", String.format("\"%s\"", jnpfKey));//字符串
                        map.put("jnpfKeyType", fieldType);
                        map.put("filedName", String.format("\"%s\"", field));

                        if(StringUtils.isBlank(fieldValueJnpfKey)){
                            map.put("jnpfValueKey",  String.format("\"%s\"", JnpfKeyConsts.POSSELECT));
                        }
                        else{
                            map.put("jnpfValueKey",  String.format("\"%s\"", fieldValueJnpfKey));
                        }

                        map.put("jnpfValueType", fieldValueType);

                        String jsonStr = JsonUtilEx.getObjectToString(fieldValue);
                        map.put("jnpfValue", String.format("\"%s\"", cn.hutool.core.codec.Base64.encode(jsonStr)));
                        StringSubstitutor stringSubstitutor = new StringSubstitutor(map);
                        String blankStr=CONDITION_CLASS+"belongPos( execution,${jnpfKey},${jnpfKeyType},${filedName},${jnpfValueKey},${jnpfValueType},${jnpfValue} )";
                        String replace = stringSubstitutor.replace(blankStr);
                        conditionExpressionStr.append(replace);
                        if(Boolean.TRUE.equals(isCustomLogical)){
                            groupConditionExp.append(replace);
                        }
                    }
                    else if("belongGroup".equals(symbol)){
                        Map map = new HashMap<>();
                        map.put("jnpfKey", String.format("\"%s\"", jnpfKey));//字符串
                        map.put("jnpfKeyType", fieldType);
                        map.put("filedName", String.format("\"%s\"", field));

                        if(StringUtils.isBlank(fieldValueJnpfKey)){
                            map.put("jnpfValueKey",  String.format("\"%s\"", JnpfKeyConsts.GROUPSELECT));
                        }
                        else{
                            map.put("jnpfValueKey",  String.format("\"%s\"", fieldValueJnpfKey));
                        }

                        map.put("jnpfValueType", fieldValueType);

                        String jsonStr = JsonUtilEx.getObjectToString(fieldValue);
                        map.put("jnpfValue", String.format("\"%s\"", cn.hutool.core.codec.Base64.encode(jsonStr)));
                        StringSubstitutor stringSubstitutor = new StringSubstitutor(map);
                        String blankStr=CONDITION_CLASS+"belongGroup( execution,${jnpfKey},${jnpfKeyType},${filedName},${jnpfValueKey},${jnpfValueType},${jnpfValue} )";
                        String replace = stringSubstitutor.replace(blankStr);
                        conditionExpressionStr.append(replace);
                        if(Boolean.TRUE.equals(isCustomLogical)){
                            groupConditionExp.append(replace);
                        }
                    }
                    else{

                    }

                    if(groups.size()>=1 && j!=(groups.size()-1)){
                        conditionExpressionStr.append("  "+logic+"  ");

                        if(Boolean.TRUE.equals(isCustomLogical)){
                            groupConditionExp.append("  "+logic+"  ");
                            groupConditionMap.put(properCond.getId(),groupConditionExp.toString());
                        }
                    }
                    if(groups.size()>=1 && j==(groups.size()-1)){
                        if(Boolean.TRUE.equals(isCustomLogical)){
                            groupConditionExp.append("  ");
                            groupConditionMap.put(properCond.getId(),groupConditionExp.toString());
                        }
                    }

                    if(i==(groups.size()-1)){
                        conditionExpressionStr.append(" ");
                    }


                }


                conditionExpressionStr.append(" ) ");



                String logic = properCond.getLogic();
                if(conditions.size()>1 && i!=(conditions.size()-1) ){
                    if("and".equals(logic)){
                        conditionExpressionStr.append(" && ");
                    }
                    else{
                        conditionExpressionStr.append(" || ");
                    }
                }

            }
            conditionExpressionStr.append("}");
            if(Boolean.FALSE.equals(isCustomLogical)){
                if(to.startsWith(SWERVE_TASK_PREFIX)){
                    //
                    properties.setSwerveConditionExpressionStr(conditionExpressionStr.toString());
                    return SEQUENCE_FLOW_WITH_CONDITION_EXPRESSION;
                }
                else{
                    return conditionExpressionStr.toString();
                }


            }
            else{
                StringBuilder conditionExpStr=new StringBuilder();
                conditionExpStr.append("${ ");
                //替换 并放入
                if(CollUtil.isNotEmpty(groupConditionMap)){
                    for (CustomConditionGroupConfig customConditionGroupConfig : customLogical) {
                        String label = customConditionGroupConfig.getLabel();
                        Object value = customConditionGroupConfig.getValue();
                        String type = customConditionGroupConfig.getType();
                        if(StringUtils.isNotBlank(type) && "group".equals(type)){
                            String s = groupConditionMap.get(Long.valueOf(value.toString()));
                            conditionExpStr.append(" "+s+" ");
                        }
                        else{
                            conditionExpStr.append(" "+value+" ");
                        }
                    }
                }
                conditionExpStr.append(" } ");


                if(to.startsWith(SWERVE_TASK_PREFIX)){
                    //
                    properties.setSwerveConditionExpressionStr(conditionExpStr.toString());
                    return SEQUENCE_FLOW_WITH_CONDITION_EXPRESSION;
                }
                else{
                    return  conditionExpStr.toString();
                }


            }
        }
        else{
            Map map = new HashMap<>();
            map.put("nodeId", String.format("\"%s\"", nodeId));//字符串
            StringSubstitutor stringSubstitutor = new StringSubstitutor(map);

            String blankStr=CONDITION_CLASS+"devMode( execution,${nodeId} ) ";
            String replace = stringSubstitutor.replace(blankStr);

            String prefix="${ ";
            String suffix=" }";
            return prefix+replace+suffix;
        }

    }


    public static Map<String, Object> formData(Map<String, Object> formData, List<FlowAssignModel> assignListAll, String processInstanceId) {
        HistoryService historyService = SpringContextHolder.getBean(HistoryService.class);
        FlowTaskUtil flowTaskUtil = SpringContextHolder.getBean(FlowTaskUtil.class);

        for (FlowAssignModel flowAssignModel : assignListAll) {
            String nodeId = flowAssignModel.getNodeId();
            List<RuleListModel> ruleList = flowAssignModel.getRuleList();
            //获取之前节点的数据
            List<HistoricTaskInstanceEntity> inCache = CommandContextUtil.getEntityCache().findInCache(HistoricTaskInstanceEntity.class);
            List<HistoricTaskInstance> historicTaskInstances = historyService.createHistoricTaskInstanceQuery().processInstanceId(processInstanceId)
                    .taskDefinitionKey(nodeId).listPage(0, 1);
            List<HistoricTaskInstance> dbList= new ArrayList<>();
            dbList.addAll(inCache);
            dbList.addAll(historicTaskInstances);
            String formKey="";
            for (HistoricTaskInstance historicTaskInstanceEntity : dbList) {
                if(historicTaskInstanceEntity.getTaskDefinitionKey().equals(nodeId)){
                    formKey=historicTaskInstanceEntity.getFormKey();
                    break;
                }
            }

            //索引0 是 formId,  1是 业务主键
            String[] split = formKey.split(BasicActivitiConstants.taskDescriptionSeparator);
            Map<String, Object> result = flowTaskUtil.infoDataAsync(split[0], split[1]);
            FlowModel flowModel =new FlowModel();
            flowModel.setFormData(result);
            FlowModel model = JsonUtil.getJsonToBean(flowModel, FlowModel.class);
            result=model.getFormData();
            for (RuleListModel assignMode : ruleList) {
                /**
                 * 数据传递
                 * 暂时应该这样规定
                 *
                 * 当前共有  主表   从表    子表   3种结构
                 *
                 * 1.允许主 从 表之间相互传递 不受影响
                 * 2.允许主 传子
                 * 3.不允许子传主
                 *  主表字段    单纯的  字段名称 比如  F_Name
                 *  从表字段        jnpf_从表表名_jnpf_从表字段名
                 *  子表字段    tableField118   value是List<JSONOBject></JSONOBject>
                 *
                 *
                 *  [
                 *     {
                 *         "nodeId": "SpGwdnF",
                 *         "ruleList": [
                 *             {

                 *             },
                 *             {
                 *                 "childField": "F_BusinessPeople",
                 *                 "parentField": "F_OutStorage"
                 *             },
                 *
                 *             {
                 *                 "childField": "tableField109-F_GoodsName",
                 *                 "parentField": "tableField109-F_GoodsName"
                 *             },
                 *             {
                 *                 "childField": "tableField109-F_GoodsName",
                 *                 "parentField": "tableField109-F_Specifications"
                 *             },
                 *             {
                 *                 "childField": "tableField109-F_Unit",
                 *                 "parentField": "tableField109-F_Unit"
                 *             },
                 *             {
                 *                 "childField": "F_CustomerName",
                 *                 "parentField": "jnpf_test_warehousing_jnpf_F_Purchase_number"
                 *             }
                 *         ]
                 *     }
                 * ]
                 *
                 * 主传主 :
                 *    map中多一个  K V
                 * 主传子
                 *   主没有: subField:[{}]
                 *   主有:  主有多少条, 更新多少次
                 */


                String parentField = assignMode.getParentField();
                String[] parentFieldList = parentField.split("-");
                String childField = assignMode.getChildField();
                String[] childFieldList = childField.split("-");

                //内置参数 或者主对主
                if(PREV_FORM_ID.equals(parentField) || parentFieldList.length==1){
                    Object id = getSysParamData(result, parentField);
                    if(ObjectUtils.isEmpty(id)){

                    }
                    else{
                        //主对主  主对副
                        /**
                         "parentField": "@prevNodeFormId"
                         "childField": "F_Warehouse",
                         */
                        if(childFieldList.length==1){
                            formData.put(childField,id);
                        }
                        //主传子
                        else if(childFieldList.length>1){
                            //判断子表里面有没有数据/ .如果没有 放1条, 如果有 有多少条更新多少条
                            List<Map<String, Object>> childList = (List<Map<String, Object>>) formData.get(childFieldList[0]);
                            if(CollUtil.isEmpty(childList)){
                                List<Map<String,Object>> subList=new ArrayList<>();
                                Map<String,Object> subMap=new HashMap<>();
                                subMap.put(childFieldList[1],id);
                                subList.add(subMap);
                                formData.put(childFieldList[0],subList);
                            }
                            //
                            else{
                                for (Map<String, Object> map : childList) {
                                    map.put(childFieldList[1],id);
                                }
                                formData.put(childFieldList[0],childList);
                            }
                        }
                    }
                }
                else{
                    List<Map<String, Object>> parentList = (List<Map<String, Object>>) result.get(parentFieldList[0]);
                    List<Map<String, Object>> childList = (List<Map<String, Object>>) formData.get(childFieldList[0]);

                    if(CollUtil.isEmpty(parentList)){
                        //什么都不传递
                    }
                    else {
                        /**
                         "parentField": "tableField109-F_Unit"
                         "childField": "tableField109-F_Unit",
                         */
                        if(CollUtil.isEmpty(childList)){
                            List<Map<String,Object>> subList= new ArrayList<>();
                            for (Map<String, Object> map : parentList) {
                                Map<String,Object> subMap= new HashMap<>();
                                Object o = map.get(parentFieldList[1]);
                                if(o!=null){
                                    subMap.put(childFieldList[1],o);
                                }
                                subList.add(subMap);
                            }
                            formData.put(childFieldList[0],subList);
                        }
                        else{
                            for (int i = 0; i < parentList.size(); i++) {
                                Map<String, Object> map = parentList.get(i);
                                Object o = map.get(parentFieldList[1]);
                                Map<String, Object> childMap = childList.get(i);
                                childMap.put(childFieldList[1],o);
                            }
                            formData.put(childFieldList[0],childList);
                        }
                    }

                }
            }
        }
        return formData;
    }

    /**
     * 处理系统参数：
     *
     * @prevNodeFormId上节点表单id
     */
    private static Object getSysParamData(Map<String, Object> formData, String parentField) {
        Object data;
        if ("@prevNodeFormId".equals(parentField)) {
            data = formData.get("id");
        } else {
            data = formData.get(parentField);
        }
        return data;
    }



    /**
     * 条件表达式
     *
     * @param logic
     */
    public static String search(String logic) {
        return SearchMethodEnum.And.getSymbol().equalsIgnoreCase(logic) ? "&&" : "||";
    }

    /**
     * 条件数据修改
     *
     * @param conditionModel
     * @param value
     */
    public static Object filedValue(FlowConditionModel conditionModel, Object value, String jnpfKey, Object form) {
        UserInfo userInfo = conditionModel.getUserInfo();
        if ("currentUser".equals(value)) {
            value = userInfo.getUserId();
        }
        try {
            try {
                List<List<String>> dataAll = JsonUtil.getJsonToBean(String.valueOf(value), List.class);
                List<String> id = new ArrayList<>();
                for (List<String> data : dataAll) {
                    id.addAll(data);
                }
                value = String.join(",", id);
            } catch (Exception e) {
                try {
                    List<String> id = new ArrayList<>();
                    List<String> dataAll = JsonUtil.getJsonToList(String.valueOf(value), String.class);
                    if (JnpfKeyConsts.CURRORGANIZE.equals(jnpfKey)) {
                        value = dataAll.stream().filter(t -> t.equals(form)).findFirst().orElse(null);
                    } else {
                        for (String data : dataAll) {
                            id.add(data);
                        }
                        value = String.join(",", id);
                    }
                } catch (Exception e1) {

                }
            }
        } catch (Exception e) {

        }
        if (value instanceof CharSequence) {
            value = "'" + value + "'";
        }
        return value;
    }

    /**
     * 条件数据修改
     *
     * @param conditionModel
     * @param value
     */
    public static Object filedData(FlowConditionModel conditionModel, Object value, String jnpfKey, Object form) {
        Map<String, Object> map = JsonUtil.stringToMap(conditionModel.getData());
        value = map.get(value);
        UserEntity userEntity = conditionModel.getUserEntity();
        FlowTaskEntity flowTaskEntity = conditionModel.getFlowTaskEntity();
        try {
            try {
                List<List<String>> dataAll = JsonUtil.getJsonToBean(String.valueOf(form), List.class);
                List<String> id = new ArrayList<>();
                for (List<String> data : dataAll) {
                    id.addAll(data);
                }
                value = String.join(",", id);
            } catch (Exception e) {
                try {
                    List<String> id = new ArrayList<>();
                    List<String> dataAll = JsonUtil.getJsonToList(String.valueOf(form), String.class);
                    if (JnpfKeyConsts.CURRORGANIZE.equals(jnpfKey)) {
                        value = dataAll.stream().filter(t -> t.equals(form)).findFirst().orElse(null);
                    } else {
                        for (String data : dataAll) {
                            id.add(data);
                        }
                        value = String.join(",", id);
                    }
                } catch (Exception e1) {

                }
            }
            if (JnpfKeyConsts.CREATETIME.equals(jnpfKey)) {
                value = flowTaskEntity.getCreatorTime().getTime() + "";
            } else if (JnpfKeyConsts.CREATEUSER.equals(jnpfKey)) {
                value = flowTaskEntity.getCreatorUserId();
            } else if (JnpfKeyConsts.CURRORGANIZE.equals(jnpfKey)) {
                value = userEntity.getOrganizeId();
            } else if (JnpfKeyConsts.CURRPOSITION.equals(jnpfKey)) {
                value = userEntity.getPositionId();
            } else if (JnpfKeyConsts.MODIFYTIME.equals(jnpfKey)) {
                value = flowTaskEntity.getLastModifyTime().getTime() + "";
            } else if (JnpfKeyConsts.MODIFYUSER.equals(jnpfKey)) {
                value = flowTaskEntity.getLastModifyUserId();
            }
        } catch (Exception e) {

        }
        if (value instanceof CharSequence) {
            value = "'" + value + "'";
        }
        return value;
    }

    /**
     * 表单数据修改
     *
     * @param form
     */
    public static Object formValue(FlowConditionModel conditionModel, String jnpfKey, Object form) {
        Object result = form;
        UserEntity userEntity = conditionModel.getUserEntity();
        FlowTaskEntity flowTaskEntity = conditionModel.getFlowTaskEntity();
        try {
            try {
                List<List<String>> dataAll = JsonUtil.getJsonToBean(String.valueOf(form), List.class);
                List<String> id = new ArrayList<>();
                for (List<String> data : dataAll) {
                    id.addAll(data);
                }
                result = String.join(",", id);
            } catch (Exception e) {
                try {
                    List<String> id = new ArrayList<>();
                    List<String> dataAll = JsonUtil.getJsonToList(String.valueOf(form), String.class);
                    for (String data : dataAll) {
                        id.add(data);
                    }
                    result = String.join(",", id);
                } catch (Exception e1) {
                }
            }
            if (JnpfKeyConsts.CREATETIME.equals(jnpfKey)) {
                result = flowTaskEntity.getCreatorTime().getTime() + "";
            } else if (JnpfKeyConsts.CREATEUSER.equals(jnpfKey)) {
                result = flowTaskEntity.getCreatorUserId();
            } else if (JnpfKeyConsts.CURRORGANIZE.equals(jnpfKey)) {
                result = userEntity.getOrganizeId();
            } else if (JnpfKeyConsts.CURRPOSITION.equals(jnpfKey)) {
                result = userEntity.getPositionId();
            } else if (JnpfKeyConsts.MODIFYTIME.equals(jnpfKey)) {
                result = flowTaskEntity.getLastModifyTime().getTime() + "";
            } else if (JnpfKeyConsts.MODIFYUSER.equals(jnpfKey)) {
                result = flowTaskEntity.getLastModifyUserId();
            }
        } catch (Exception e) {
        }
        if (result instanceof CharSequence) {
            result = "'" + result + "'";
        }
        return result;
    }

    /**
     * 表达式
     */
    public static Object formula(GroupsModel properCond, Map<String, Object> data) {
        String result = null;
        try {
            StringBuilder builder = new StringBuilder();
            builder.append("function getNum(val) {\n" +
                    "  return isNaN(val) ? 0 : Number(val)\n" +
                    "};\n" +
                    "// 求和\n" +
                    "function SUM() {\n" +
                    "  var value = 0\n" +
                    "  for (var i = 0; i < arguments.length; i++) {\n" +
                    "    value += getNum(arguments[i])\n" +
                    "  }\n" +
                    "  return value\n" +
                    "};\n" +
                    "// 求差\n" +
                    "function SUBTRACT(num1, num2) {\n" +
                    "  return getNum(num1) - getNum(num2)\n" +
                    "};\n" +
                    "// 相乘\n" +
                    "function PRODUCT() {\n" +
                    "  var value = 1\n" +
                    "  for (var i = 0; i < arguments.length; i++) {\n" +
                    "    value = value * getNum(arguments[i])\n" +
                    "  }\n" +
                    "  return value\n" +
                    "};\n" +
                    "// 相除\n" +
                    "function DIVIDE(num1, num2) {\n" +
                    "  return getNum(num1) / (getNum(num2) === 0 ? 1 : getNum(num2))\n" +
                    "};\n" +
                    "// 获取参数的数量\n" +
                    "function COUNT() {\n" +
                    "  var value = 0\n" +
                    "  for (var i = 0; i < arguments.length; i++) {\n" +
                    "    value ++\n" +
                    "  }\n" +
                    "  return value\n" +
                    "};\n");
            String field1 = properCond.getField();
            String str= StringUtils.isBlank(field1)?properCond.getFieldName():field1;
            String field = field(str, data, null);
            ScriptEngine scriptEngine = SpringContextHolder.getBean(ScriptEngine.class);
            String eval = builder.toString() + " var result = " + field + ";";
            scriptEngine.eval(eval);
            double d = (double) scriptEngine.get("result");
            NumberFormat nf = NumberFormat.getNumberInstance();
            nf.setRoundingMode(RoundingMode.UP);
            result = nf.format(d);
        } catch (Exception e) {
            System.out.println(e.getMessage());
        }
        return result;
    }
    /**
     * 替换文本值
     *
     * @param content
     * @param data
     * @return
     */
    public static String field(String content, Map<String, Object> data, String type) {
        String pattern = "[{]([^}]+)[}]";
        Pattern patternList = Pattern.compile(pattern);
        Matcher matcher = patternList.matcher(content);
        Map<String, List<String>> parameterMap = data(matcher, data);
        Map<String, Object> result = new HashMap<>();
        if (StringUtils.isNotEmpty(type)) {
            Map<String, String> datas = new HashMap<>();
            for (String key : parameterMap.keySet()) {
                datas.put(key, data.get(key) != null ? String.valueOf(data.get(key)) : "");
            }
            result.putAll(datas);
        } else {
            Map<String, Object> dataAll = new HashMap<>();
            for (String key : parameterMap.keySet()) {
                StringJoiner joiner = new StringJoiner(",");
                List<String> list = parameterMap.get(key);
                for (String id : list) {
                    joiner.add("'" + id + "'");
                }
                String value = joiner.toString();
                if (list.size() > 1) {
                    value = "SUM(" + joiner.toString() + ")";
                }
                dataAll.put(key, value);
            }
            result.putAll(dataAll);
        }
        StringSubstitutor strSubstitutor = new StringSubstitutor(result, "{", "}");
        String field = strSubstitutor.replace(content);
        return field;
    }

    /**
     * 赋值
     */
    public static Map<String, List<String>> data(Matcher matcher, Map<String, Object> dataAll) {
        Map<String, List<String>> map = new HashMap<>();
        Map<String, String> keyAll = new HashMap<>();
        while (matcher.find()) {
            String group = matcher.group().replaceAll("\\{", "").replaceAll("}", "");
            keyAll.put(group, group);
        }
        for (String id : keyAll.keySet()) {
            List<String> valueData = new ArrayList<>();
            String valueAll[] = id.split("-");
            String key = valueAll[0];
            Object childDataAll = dataAll.get(key) != null ? dataAll.get(key) : "";
            if (valueAll.length > 1) {
                String data = valueAll[1];
                if (childDataAll instanceof List) {
                    List<Map<String, Object>> childData = (List<Map<String, Object>>) childDataAll;
                    for (Map<String, Object> childDatum : childData) {
                        Object childDatas = childDatum.get(data);
                        valueData.add(childDatas + "");
                    }
                }
            } else if (valueAll.length == 1) {
                valueData.add(childDataAll + "");
            }
            map.put(id, valueData);
        }
        return map;
    }

}
